package com.google.common.collect;

import java.util.*;

public class HashMultimap<K, V> implements Multimap<K, V> {
    private final Map<K, Collection<V>> Items = new HashMap<>();

    public HashMultimap() {
    }

    public Map<K, Collection<V>> asMap() {
        return Items;
    }

    @Override
    public int size() {
        return Items.size();
    }

    @Override
    public void put(K k, V v) {
        Collection<V> list = Items.get(k);
        if(list == null){
            list = new LinkedList<>();
        }
        list.add(v);
    }

    @Override
    public void putAll(K k, Collection<V> vs) {
        Collection<V> list = Items.get(k);
        if(list == null){
            list = new LinkedList<>();
        }
        list.addAll(vs);
    }

    @Override
    public Set<K> keySet() {
        return Items.keySet();
    }

    @Override
    public Set<Map.Entry<K, Collection<V>>> entries() {
        return Items.entrySet();
    }

    @Override
    public Collection<V> get(K k) {
        return Items.get(k);
    }

    @Override
    public int hashCode() {
        return asMap().hashCode();
    }

    @Override
    public String toString() {
        return asMap().toString();
    }
}
